#!/usr/bin/env python
#coding: utf-8
'''
Created on 2017年4月22日

@author: Administrator
'''
from article.models import Article
from django.db.models.signals import post_save
from django.dispatch.dispatcher import receiver
from article.tasks import update_article_img_src_task
from article.utils.es_article import update_article_to_es

@receiver(post_save, sender=Article, dispatch_uid='article.article_save')
def article_save_handler(sender, instance, raw, created, **kwargs):
    '''
    '''
    #更新内容img src
    update_article_img_src_task.delay(instance.id, instance.content)
    
    #更新es
    update_article_to_es(instance)
    
def update_article_by_user(user):
    '''
    function: 
    '''
    #定义es
    articles = Article.objects.filter(user=user)
    update_article_to_es(articles)
